package com.isay.frameworklib.utils.glide;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.isay.frameworklib.R;

import java.io.File;

/**
 * Created by cywu4 on 2018/8/8.
 */

public class GlideUtils {


    /**
     * 加载url图片
     */
    public static void loadImage(Context context, ImageView imageView, String url) {
        if (context != null) {
            GlideApp.with(context)
                    .load(url)
                    .fitCenter()
                    .into(imageView);
        }
    }

    /**
     * 加载url图片
     */
    public static void loadImage(Context context, ImageView imageView, String url, int errorDrawableId) {
        if (context != null) {
            GlideApp.with(context)
                    .load(url)
                    .error(errorDrawableId)
                    .fitCenter()
                    .into(imageView);
        }
    }

    /**
     * 加载url图片，缩略图
     */
    public static void loadImageMultiplierWidthAnim(Context context, ImageView imageView, String url) {
        if (context != null) {
            GlideApp.with(context)
                    .load(url)
                    .fitCenter()
                    .thumbnail(0.4f)
                    .transition(DrawableTransitionOptions.withCrossFade(400))
                    .into(imageView);
        }
    }


    /**
     * 加载url图片
     */
    public static void loadImageAnim(Context context, ImageView imageView, String url) {
        if (context != null) {
            GlideApp.with(context)
                    .load(url)
                    .fitCenter()
                    .transition(DrawableTransitionOptions.withCrossFade(400))
                    .into(imageView);
        }
    }


    /**
     * 加载File文件图片
     */
    public static void loadImage(Context context, ImageView imageView, File file) {
        if (context != null && file != null && file.exists()) {
            GlideApp.with(context)
                    .load(file)
                    .fitCenter()
                    .into(imageView);
        }
    }

    /**
     * 加载url图片
     */
    public static void loadImageCircleCropWidthAnim(Context context, ImageView imageView, String url) {
        if (context != null) {
            GlideApp.with(context)
                    .load(url)
                    .fitCenter()
                    .transition(DrawableTransitionOptions.withCrossFade(400))
                    .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                    .into(imageView);
        }
    }


    /**
     * 加载gif图片
     */
    public static void loadGif(Context context, ImageView imageView, int drawableId) {
        GlideApp.with(context)
                .load(drawableId)
                .transition(DrawableTransitionOptions.withCrossFade(400))
                .into(imageView);
    }


}
